home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chef 1.1 so Folder / Chef ƒ / MSG Shell ƒ / msg menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  3.9 KB  |  194 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg menus.c
  4.  
  5. Purpose:    This module handles menu selections.
  6.  
  7.  
  8.  
  9. Chef -=- convert text to Swedish chef talk
  10. Copyright ©1994, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg graphics.h"
  30. #include "msg menus.h"
  31. #include "msg help.h"
  32. #include "msg prefs.h"
  33. #include "msg environment.h"
  34. #include "program globals.h"
  35. #include "chef.h"
  36.  
  37. MenuHandle        gAppleMenu;
  38. MenuHandle        gFileMenu;
  39. MenuHandle        gEditMenu;
  40. MenuHandle        gOptionsMenu;
  41. MenuHandle        gHelpMenu;
  42.  
  43. void AdjustMenus(void)
  44. {
  45.     WindowPeek        theWindow;
  46.     int                kind;
  47.     int                i;
  48.     unsigned char    iter;
  49.     
  50.     if (!gInProgress)
  51.     {
  52.         EnableItem(gAppleMenu, aboutItem);
  53.         EnableItem(gAppleMenu, aboutMSGItem);
  54.         EnableItem(gAppleMenu, helpItem);
  55.         EnableItem(gFileMenu, 0);
  56.         EnableItem(gEditMenu, 0);
  57.         EnableItem(gOptionsMenu, 0);
  58.     }
  59.     else
  60.     {
  61.         DisableItem(gAppleMenu, aboutItem);
  62.         DisableItem(gAppleMenu, aboutMSGItem);
  63.         DisableItem(gAppleMenu, helpItem);
  64.         DisableItem(gFileMenu, 0);
  65.         DisableItem(gEditMenu, 0);
  66.         DisableItem(gOptionsMenu, 0);
  67.     }
  68.     
  69.     theWindow = (WindowPeek)FrontWindow();
  70.     kind = theWindow ? theWindow->windowKind : 0;
  71.     
  72.     if(kind < 0)
  73.         EnableItem(gEditMenu, 0);
  74.     else
  75.         DisableItem(gEditMenu, 0);
  76.     
  77.     if(theWindow)
  78.         EnableItem(gFileMenu, closeItem);
  79.     else
  80.         DisableItem(gFileMenu, closeItem);
  81.     
  82.     CheckItem(gOptionsMenu, showSaveItem, gShowSaveDialog);
  83.     CheckItem(gOptionsMenu, addSuffixItem, gAddSuffix);
  84.     CheckItem(gOptionsMenu, showProgressItem, gShowProgress);
  85.     CheckItem(gOptionsMenu, rtfItem, gUseRTF);
  86. }
  87.  
  88. void HandleMenu(long mSelect)
  89. {
  90.     int            menuID = HiWord(mSelect);
  91.     int            menuItem = LoWord(mSelect);
  92.     
  93.     switch (menuID)
  94.     {
  95.         case appleMenu:
  96.             HandleAppleMenu(menuItem);
  97.             break;
  98.         case fileMenu:
  99.             HandleFileMenu(menuItem);
  100.             break;    
  101.         case editMenu:
  102.             HandleEditMenu(menuItem);
  103.             break;
  104.         case optionsMenu:
  105.             HandleOptionsMenu(menuItem);
  106.             break;
  107.         case helpMenu:
  108.             HandleHelpMenu(menuItem);
  109.             break;
  110.       }
  111. }
  112.  
  113. void HandleAppleMenu(int menuItem)
  114. {
  115.     GrafPtr        savePort;
  116.     Str255        name;
  117.     
  118.     if(menuItem == 1)
  119.         OpenTheWindow(kAbout);
  120.     if (menuItem == 2)
  121.         OpenTheWindow(kAboutMSG);
  122.     else if(menuItem > 4)
  123.     {
  124.         GetPort(&savePort);
  125.         GetItem(gAppleMenu, menuItem, name);
  126.         OpenDeskAcc(name);
  127.         SetPort(savePort);
  128.     }
  129. }
  130.  
  131. void HandleFileMenu(int menuItem)
  132. {
  133.     WindowPtr            theWindow;
  134.     int                    i;
  135.     Boolean                gotone;
  136.     
  137.     switch (menuItem)
  138.     {
  139.         case openItem:
  140.             NewConvert();
  141.             break;
  142.         case closeItem:
  143.             theWindow=FrontWindow();
  144.             gotone=FALSE;
  145.             for (i=0; (i<NUM_WINDOWS) && (!gotone); i++)
  146.                 gotone=(theWindow==gTheWindow[i]);
  147.                 
  148.             if (gotone)
  149.                 CloseTheWindow(i-1);
  150.             else
  151.                 DisposeWindow(theWindow);
  152.             
  153.             AdjustMenus();
  154.             break;
  155.         case quitItem:
  156.             gDone = TRUE;
  157.             break;
  158.     }
  159. }
  160.  
  161. void HandleEditMenu(int menuItem)
  162. {
  163.     SystemEdit(menuItem - 1);
  164. }
  165.  
  166. void HandleHelpMenu(int menuItem)
  167. {
  168.     gWhichHelp=menuItem;
  169.     UpdateHelpWindow();
  170. }
  171.  
  172. void HandleOptionsMenu(int menuItem)
  173. {
  174.     switch (menuItem)
  175.     {
  176.         case showSaveItem:
  177.             gShowSaveDialog=!gShowSaveDialog;
  178.             SaveThePrefs();
  179.             break;
  180.         case addSuffixItem:
  181.             gAddSuffix=!gAddSuffix;
  182.             SaveThePrefs();
  183.             break;
  184.         case showProgressItem:
  185.             gShowProgress=!gShowProgress;
  186.             SaveThePrefs();
  187.             break;
  188.         case rtfItem:
  189.             gUseRTF=!gUseRTF;
  190.             SaveThePrefs();
  191.             break;
  192.     }
  193. }
  194.